//这里书写属性相关的API文件
import request from "@/utils/request.ts";
import type {CategoryResponseData,AttrResponseData,Attr} from './type.ts'
//接口地址
enum API {
    C1_URL='/admin/product/getCategory1', //一级分类
    C2_URL='/admin/product/getCategory2/',//二级分类
    C3_URL='/admin/product/getCategory3/',//三级分类
    ATTR_URL='/admin/product/attrInfoList/',// 获取分类下已有的属性与属性值
    ADDORUPDATEATTR_URL='/admin/product/saveAttrInfo',//修改或新增属性值
    DELETEATTR_URL='/admin/product/deleteAttr/',//删除一个属性
    
}

/**
 * 获取一级分类的接口方法
 */
export const reqC1=()=>request.get<any,CategoryResponseData>(API.C1_URL)
/**
 *获取二级分类接口的方法
 * @param category1Id
 */
export const reqC2=(category1Id:number|string)=>request.get<any,CategoryResponseData>(API.C2_URL+category1Id)
/**
 * 获取三级分类接口的方法
 * @param category2Id
 */
export const reqC3=(category2Id:number|string)=>request.get<any,CategoryResponseData>(API.C3_URL+category2Id)
/**
 * 获取attr
 * @param category1Id
 * @param category2Id
 * @param category3Id
 */
export const reqAttr = (category1Id:string|number,category2Id:string|number,category3Id:string|number) => {
  return request.get<any,AttrResponseData>(API.ATTR_URL+`${category1Id}/${category2Id}/${category3Id}`)
}
/**
 * 添加或修改属性
 * @param data
 */
export const reqAddOrUpdateAttr = (data:Attr) => {
  return request.post<any,any>(API.ADDORUPDATEATTR_URL,data)
}
/**
 * 删除一个属性
 * @param attrId
 */
export const reqRemoveAttr = (attrId:number) => {
    return request.delete<any,any>(API.DELETEATTR_URL+attrId)
}